

package com.viweb.storemanager.core;

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.WindowConstants;


public class BaseMainFrame extends JFrame {

    private JMenuBar menuBar;
    private JToolBar toolBar;
    private CommonStatusBar statusBar;
    private JPanel homePanel;
    private JPanel container;
    private BaseDesktopPane desktopPane;
    private String applicationTitle;

    /** Creates a new instance of BaseMainFrame */
    public BaseMainFrame(String applicationTitle, JMenuBar menuBar, JToolBar toolBar, JPanel homePanel) {

        this.applicationTitle = applicationTitle;
        this.menuBar = menuBar;
        this.toolBar = toolBar;
        this.homePanel = homePanel;

        this.initComponents();
    }

    private void initComponents() {
        this.setTitle(this.applicationTitle);
        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        this.setFont(new java.awt.Font("Tahoma", 0, 12));

        this.setJMenuBar(this.menuBar);
        this.getContentPane().add(this.toolBar, BorderLayout.NORTH);

        this.desktopPane = new BaseDesktopPane();
        this.desktopPane.setParent(this);
        this.desktopPane.registerMenuBar(this.menuBar);
        this.desktopPane.setHomeScreenPanel(this.homePanel);
        
        this.pack();
    }

    public void addContainer(JPanel container) {
        this.container = container;
        this.getContentPane().add(this.container, BorderLayout.CENTER);

        this.pack();
    }

    public void addStatusBar(CommonStatusBar statusBar) {
        this.statusBar = statusBar;
        this.getContentPane().add(this.statusBar.getBar(), BorderLayout.SOUTH);
        this.pack();
    }

    public BaseDesktopPane getDesktopPane() {
        return this.desktopPane;
    }

    public void showToolbar(boolean visible) {
        this.toolBar.setVisible(visible);
    }

    public void showStatusBar(boolean visible) {
        this.statusBar.getBar().setVisible(visible);
    }

    public void setApplicationTitle(String applicationTitle) {
        this.applicationTitle = applicationTitle;
    }

    public void setDefaultTitle() {
        this.setTitle(this.applicationTitle);
    }

    public void setMDIModelTitle(String mdiFrameTitle) {
        this.setTitle(this.applicationTitle + " - " + mdiFrameTitle);
    }

    public void setCurrentStatus(String status) {
        this.statusBar.setCurrentStatus(status);
    }

    public void setCurrentUsername(String username) {
        this.statusBar.setCurrentUsername(username);
    }
}